//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "GaussKronrodNonAdaptive.h"
using namespace Cephei::QL::Math::Integrals;
#include <gen/QL/Math/Integrals/Integrator.h>
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Math::Integrals::CGaussKronrodNonAdaptive::CGaussKronrodNonAdaptive (Double absoluteAccuracy, UInt64 maxEvaluations, Double relativeAccuracy) : CIntegrator(CGaussKronrodNonAdaptive::typeid)
{
    try
    {
#ifdef HANDLE
        _phGaussKronrodNonAdaptive = NULL;
#endif
        QuantLib::Real _absoluteAccuracy = (QuantLib::Real)ValueHelper::Convert (absoluteAccuracy);
        QuantLib::Size _maxEvaluations = (QuantLib::Size)ValueHelper::Convert (maxEvaluations);
        QuantLib::Real _relativeAccuracy = (QuantLib::Real)ValueHelper::Convert (relativeAccuracy);
        _ppGaussKronrodNonAdaptive = new boost::shared_ptr<QuantLib::GaussKronrodNonAdaptive> (new QuantLib::GaussKronrodNonAdaptive ( _absoluteAccuracy,  _maxEvaluations,  _relativeAccuracy ));
        SetIntegrator (boost::dynamic_pointer_cast<QuantLib::Integrator> (*_ppGaussKronrodNonAdaptive));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Math::Integrals::CGaussKronrodNonAdaptive::CGaussKronrodNonAdaptive (boost::shared_ptr<QuantLib::GaussKronrodNonAdaptive>& childNative, Object^ owner) : CIntegrator(CGaussKronrodNonAdaptive::typeid)
{
#ifdef HANDLE
	_phGaussKronrodNonAdaptive = NULL;
#endif
	_ppGaussKronrodNonAdaptive = &childNative;
    _ppIntegrator = new boost::shared_ptr<QuantLib::Integrator> (boost::dynamic_pointer_cast<QuantLib::Integrator> (*_ppGaussKronrodNonAdaptive));
}
Cephei::QL::Math::Integrals::CGaussKronrodNonAdaptive::CGaussKronrodNonAdaptive (QuantLib::GaussKronrodNonAdaptive& childNative, Object^ owner) : CIntegrator(CGaussKronrodNonAdaptive::typeid)
{
#ifdef HANDLE
	_phGaussKronrodNonAdaptive = NULL;
#endif
	_ppGaussKronrodNonAdaptive = new boost::shared_ptr<QuantLib::GaussKronrodNonAdaptive> (&childNative);
    _ppIntegrator = new boost::shared_ptr<QuantLib::Integrator> (boost::dynamic_pointer_cast<QuantLib::Integrator> (*_ppGaussKronrodNonAdaptive));
    _GaussKronrodNonAdaptiveOwner = owner;
    _IntegratorOwner = owner;
}

Cephei::QL::Math::Integrals::CGaussKronrodNonAdaptive::CGaussKronrodNonAdaptive (CGaussKronrodNonAdaptive^ copy) : CIntegrator(CGaussKronrodNonAdaptive::typeid)
{
#ifdef HANDLE
	_phGaussKronrodNonAdaptive = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppGaussKronrodNonAdaptive = new boost::shared_ptr<QuantLib::GaussKronrodNonAdaptive> (copy->GetShared());
        _ppIntegrator = new boost::shared_ptr<QuantLib::Integrator> (boost::dynamic_pointer_cast<QuantLib::Integrator> (*_ppGaussKronrodNonAdaptive));
    }
}
Cephei::QL::Math::Integrals::CGaussKronrodNonAdaptive::CGaussKronrodNonAdaptive (System::Type^ t) : CIntegrator(CGaussKronrodNonAdaptive::typeid)
{
#ifdef HANDLE
	_phGaussKronrodNonAdaptive = NULL;
#endif
	if (!t->IsSubclassOf(CGaussKronrodNonAdaptive::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Math::Integrals::CGaussKronrodNonAdaptive::CGaussKronrodNonAdaptive (QuantLib::Handle<QuantLib::GaussKronrodNonAdaptive>& childNative, Object^ owner)  : CIntegrator(CGaussKronrodNonAdaptive::typeid)
{
	_phGaussKronrodNonAdaptive = &childNative;
	_ppGaussKronrodNonAdaptive = &static_cast<boost::shared_ptr<QuantLib::GaussKronrodNonAdaptive>>(childNative.currentLink());
    _ppIntegrator = new boost::shared_ptr<QuantLib::Integrator> (boost::dynamic_pointer_cast<QuantLib::Integrator> (*_ppGaussKronrodNonAdaptive));
    _GaussKronrodNonAdaptiveOwner = owner;
}
Cephei::QL::Math::Integrals::CGaussKronrodNonAdaptive::CGaussKronrodNonAdaptive (QuantLib::Handle<QuantLib::GaussKronrodNonAdaptive> childNative)  : CIntegrator(CGaussKronrodNonAdaptive::typeid)
{
	_phGaussKronrodNonAdaptive = &childNative;
	_ppGaussKronrodNonAdaptive = &static_cast<boost::shared_ptr<QuantLib::GaussKronrodNonAdaptive>>(childNative.currentLink());
    _ppIntegrator = new boost::shared_ptr<QuantLib::Integrator> (boost::dynamic_pointer_cast<QuantLib::Integrator> (*_ppGaussKronrodNonAdaptive));
}
#endif
#ifdef STRUCT
Cephei::QL::Math::Integrals::CGaussKronrodNonAdaptive::CGaussKronrodNonAdaptive (QuantLib::GaussKronrodNonAdaptive childNative)  : CIntegrator(CGaussKronrodNonAdaptive::typeid)
{
#ifdef HANDLE
	_phGaussKronrodNonAdaptive = NULL;
#endif
	_ppGaussKronrodNonAdaptive = new boost::shared_ptr<QuantLib::GaussKronrodNonAdaptive> (new QuantLib::GaussKronrodNonAdaptive (childNative));
    _ppIntegrator = new boost::shared_ptr<QuantLib::Integrator> (boost::dynamic_pointer_cast<QuantLib::Integrator> (*_ppGaussKronrodNonAdaptive));
}
#endif

Cephei::QL::Math::Integrals::CGaussKronrodNonAdaptive::~CGaussKronrodNonAdaptive ()
{
    if (_ppGaussKronrodNonAdaptive != NULL)
    {
	    delete _ppGaussKronrodNonAdaptive;
        _ppGaussKronrodNonAdaptive = NULL;
    }
}
Cephei::QL::Math::Integrals::CGaussKronrodNonAdaptive::!CGaussKronrodNonAdaptive ()
{
    if (_ppGaussKronrodNonAdaptive != NULL)
    {
	    delete _ppGaussKronrodNonAdaptive;
    }
}
QuantLib::GaussKronrodNonAdaptive& Cephei::QL::Math::Integrals::CGaussKronrodNonAdaptive::GetReference ()
{
    if (_ppGaussKronrodNonAdaptive == NULL) throw gcnew NativeNullException ();
	return **_ppGaussKronrodNonAdaptive;
}
boost::shared_ptr<QuantLib::GaussKronrodNonAdaptive>& Cephei::QL::Math::Integrals::CGaussKronrodNonAdaptive::GetShared ()
{
    if (_ppGaussKronrodNonAdaptive == NULL) throw gcnew NativeNullException ();
	return *_ppGaussKronrodNonAdaptive;
}
QuantLib::GaussKronrodNonAdaptive* Cephei::QL::Math::Integrals::CGaussKronrodNonAdaptive::GetPointer ()
{
    if (_ppGaussKronrodNonAdaptive == NULL) throw gcnew NativeNullException ();
	return &**_ppGaussKronrodNonAdaptive;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::GaussKronrodNonAdaptive>& Cephei::QL::Math::Integrals::CGaussKronrodNonAdaptive::GetHandle ()
{
	if (_phGaussKronrodNonAdaptive == NULL)
	{
		_phGaussKronrodNonAdaptive = new Handle<QuantLib::GaussKronrodNonAdaptive> (*_ppGaussKronrodNonAdaptive);
	}
	return *_phGaussKronrodNonAdaptive;
}
#endif
bool Cephei::QL::Math::Integrals::CGaussKronrodNonAdaptive::HasNative () 
{
	return (_ppGaussKronrodNonAdaptive != NULL);
}

Double Cephei::QL::Math::Integrals::CGaussKronrodNonAdaptive::RelativeAccuracy::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppGaussKronrodNonAdaptive)->relativeAccuracy ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Math::Integrals::IGaussKronrodNonAdaptive^ Cephei::QL::Math::Integrals::CGaussKronrodNonAdaptive::SetRelativeAccuracy (Double prm1)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        QuantLib::Real _prm1 = (QuantLib::Real)ValueHelper::Convert (prm1);
    	(*_ppGaussKronrodNonAdaptive)->setRelativeAccuracy ( _prm1 );
    	return this;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Math::Integrals::IGaussKronrodNonAdaptive^ Cephei::QL::Math::Integrals::CGaussKronrodNonAdaptive_Factory::Create (Double absoluteAccuracy, UInt64 maxEvaluations, Double relativeAccuracy)
{
    return gcnew CGaussKronrodNonAdaptive ( absoluteAccuracy,  maxEvaluations,  relativeAccuracy);
}
